package com.simulation.web.controller.tech;

import cn.hutool.core.bean.BeanUtil;
import com.simulation.common.core.domain.AjaxResult;
import com.simulation.web.domain.TechTasks;
import com.simulation.web.dto.TechTaskDTO;
import com.simulation.web.service.TaskService;
import com.simulation.web.vo.TechTaskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 唐雄杰
 * @Date 2024-08-25 23:03
 **/
@RestController
@RequestMapping("/tasks")
public class TechTaskController {
    @Autowired
    private TaskService taskService;

    @PostMapping("createTask")
    public AjaxResult createTask(@RequestBody TechTaskDTO taskDTO) {
        TechTasks techTasks = new TechTasks();
        BeanUtil.copyProperties(taskDTO, techTasks);
        taskService.createTask(techTasks);
        return AjaxResult.success();
    }

    @PostMapping("updateTaskStatus")
    public AjaxResult updateTaskStatus(@RequestBody TechTaskDTO taskDTO) {
        taskService.updateTaskStatus(taskDTO.getId(), taskDTO.getStatus());
        return AjaxResult.success();
    }

    @PostMapping("updateTaskProgress")
    public AjaxResult updateTaskProgress(@RequestBody TechTaskDTO taskDTO) {
        taskService.updateTaskProgress(taskDTO.getId(), taskDTO.getProgress());
        return AjaxResult.success();
    }

    @PostMapping("deleteTask")
    public AjaxResult deleteTask(@RequestBody TechTaskDTO taskDTO) {
        taskService.deleteTask(taskDTO.getId());
        return AjaxResult.success();
    }

    @GetMapping("getTasksByCreateUserId")
    public AjaxResult getTasksByCreateUserId(TechTaskDTO taskDTO) {
        return AjaxResult.success(taskService.getTasksByCreateUserId(taskDTO));
    }

    @GetMapping("getTasksByTeamId")
    public AjaxResult getTaskByTeamId(TechTaskDTO techTaskDTO) {
        return AjaxResult.success(taskService.getTasksByTeamId(techTaskDTO));
    }

    @GetMapping("getTaskById")
    public AjaxResult getTaskById(TechTaskDTO taskDTO) {
        TechTaskVO task = taskService.getTaskById(taskDTO.getId(), taskDTO.getRelatedType());
        return AjaxResult.success(task);
    }
}
